class AlterAttendancesFk < ActiveRecord::Migration
  def self.up
    # Add cascade to the foreign keys so we can delete users that have attendances linked
    # to them (see issue 3)
    execute "ALTER TABLE attendances DROP FOREIGN KEY fk_attendances_users"
    execute "ALTER TABLE attendances DROP FOREIGN KEY fk_attendances_events" 
    execute "ALTER TABLE attendances ADD CONSTRAINT fk_attendances_users FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE"
    execute "ALTER TABLE attendances ADD CONSTRAINT fk_attendances_events FOREIGN KEY (event_id) REFERENCES events(id)ON DELETE CASCADE" 
  end  
 
  
  def self.down
    execute "ALTER TABLE attendances DROP FOREIGN KEY fk_attendances_users"
    execute "ALTER TABLE attendances DROP FOREIGN KEY fk_attendances_events" 
    execute "ALTER TABLE attendances ADD CONSTRAINT fk_attendances_users FOREIGN KEY (user_id) REFERENCES users(id)"
    execute "ALTER TABLE attendances ADD CONSTRAINT fk_attendances_events FOREIGN KEY (event_id) REFERENCES events(id)" 
  end
end
